﻿<!DOCTYPE>
<html  ng-app="loginApp">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, width=device-width, minimal-ui">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1" />
    <meta name="renderer" content="webkit" />
    <link href="/css/style2.css" rel="stylesheet" type="text/css" />
    <script src="/framework/angular-wang-editor/dist/js/lib/jquery-1.10.2.min.js" type="text/javascript"></script>
    <style></style>
    <title ng-bind="systemTitle"></title>
    <!--环境检查-->
    <script src="/framework/loginCheck.js" type="text/javascript"></script>
    <script src="/framework/angular.min.js"></script>
    <style type="text/css">
        .content{box-shadow:0px 9px 24px 4px #c5c5ca;border-radius:5px}
        .form-field .error,.errornum{display:block;margin-top:10px;margin-left:2px;color:#f13722}
        .container-tap{height:70px;padding:15px 22px 5px 20px}
        .zhuce{height:30px;line-height:30px;font-size:12px;margin-top:4px}
    </style>
</head>
<body ng-controller="loginCtrl" ng-cloak>
    <div class="container-tap">
        <img src="/images/logo.png" alt="" height=40>
        <div class="zhuce"><a href="/user/register.html">企业注册</a></div>
    </div>
    <div class="content" id="AppContent">
        <div class="content-left">
            <img src="/images/banner3.png" alt="">
        </div>
        <div class="content-right">
            <form  name="myForm" novalidate>
                <div class="topsigunp">登录 </div>
                <div class="form-field forminput form-field-one"><span>账号</span>  
                    <i class="icon" ></i>
                    <input type="text" ng-blur="errorInput(myForm)" ng-focus="change=false;isshow=false" placeholder="邮箱/手机号/用户名" ng-class="{'errorinput':isshow||errnum5||errnum10,'infoinput':!change}" ng-readonly="errnum5||errnum10" name="username" id="username" autocomplete="off" ng-model="username"  set-Focus="" required >
                    <span class="error"  ng-show="change"><img src="/images/icon.png"  alt="">{{inputmsg}}</span>
                </div>
                <div class="form-field forminput"><span>密码</span>    
                    <i class="icon2"></i>
                    <input type="password" ng-blur="errorInput1(myForm)" ng-focus="change1=false;isshow1=false" ng-class="{'errorinput':isshow1||errnum5||errnum10,'infoinput':!change1}" ng-readonly="errnum5||errnum10" name="password" id="password"  autocomplete="off" ng-model="password" required value="123456">
                    <span class="error"   ng-show="change1" ><img src="/images/icon.png" alt=""> {{inputmsg1}}{{loginerrmsg}}</span>
                    <span class="error"   ng-show="loginerr" ><img src="/images/icon.png" alt="">{{loginerrmsg}}</span>
                </div>
                <div class="form-field pass" ng-hide="errnum5||errnum10">
                    <div><input type="checkbox" ng-checked="!myForm.password.$error.required" ><label>记住密码</label></div>
                    <a href="/user/forget_pwd.html" class="info-wjmm">忘记密码？</a>
                </div>
                <div class="form-field yzm" ng-show="errnum5">
                    <span class="error"><img src="/images/icon.png" alt="">操作次数过多，请通过验证登录</span>
                    <input type="text"  name="" id="" placeholder="验证码">
                    <div class="getyzm">获取验证码</div>
                </div>
                <div class="errornum" ng-show="errnum10">
                    <span class="error" ><img src="/images//icon.png" alt="">操作次数过多，请稍后重试</span>
                </div>
                <div class="login" >
                    <button class="btn" ng-class="{'successBtn':username.length>0&&password.length>0,'infoBtn':errnum5||errnum10}"  ng-click="user_login()" ng-disabled="myForm.$invalid || logindis||errnum5||errnum10">登录</button>
                </div>
            </form>
            <div class="wrap">&nbsp;&nbsp;用其他方式登录&nbsp;&nbsp;</div>
            <div class="dsfdl">
                <a ng-href="{{qywxUrl}}"></a>
                <!-- <a ng-href="{{ddUrl}}"></a> -->
                <a ng-href="{{wxUrl}}">
                </a>
            </div>
        </div>
    </div>
    <footer >
        <p id="version">v2.123</p>
        <p>友情提示：为获得更好的用户体验，请使用Google Chrome浏览器</p>
        <p><a href="https://beian.miit.gov.cn" target="_blank" rel="nofollow">京ICP备14005135号</a></p>
    </footer>
    <script src="/framework/lodash.min.js" type="text/javascript"></script>
    <script src="/framework/restangular/restangular.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/framework/angular-toastr/angular-toastr.min.js"></script>
    <script type="text/javascript" src="/framework/angular-toastr/angular-toastr.tpls.min.js"></script>
    <script src="/system/service/common.js" type="text/javascript"></script>    
    <script type="text/javascript">

        var mainApp = angular.module("loginApp", ['Common', 'personnelmanagementS']);

        mainApp.directive('setFocus', function () {
            return function (scope, element) {
                element[0].focus();
            };
        });

        mainApp.controller('loginCtrl', ['$scope', '$rootScope', 'sysUserInfo', 'RequestUserService', 'RequestPopService', 'Restangular', function ($scope, $rootScope, sysUserInfo, RM, RPS, Restangular) {
            Restangular.addFullRequestInterceptor(function(element, operation, route, url, headers, params, httpConfig) {     
                    return {              
                        headers: {"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"}  
                    };
                });
			$scope.qywxUrl = commonUrl + "/ApiUser/loginByThirdParty/wechat";
            $scope.wxUrl = commonUrl + "/ApiUser/loginByThirdParty/wechatlogin";
            $scope.ddUrl = commonUrl + "/ApiUser/loginByThirdParty/ddlogin";
            $scope.logmsg = "登 录";
            $scope.errnum5 = false;
            $scope.errnum10 = false;
            $scope.logindis = false;
            $scope.valimgurl = ""; //验证码图片地址
            $scope.verify_div = false;
            $scope.isshow = false;
            $scope.isshow1 = false;
            $scope.change = false;  
            $scope.change1 = false;   
            $scope.inputmsg = '';  
            $scope.inputmsg1 = '';  


            //判断本地有没有登录数据
            try {
                $scope.usertoken = sysUserInfo.getuserinfotoken();
                $scope.oldUserinfo = JSON.parse(localStorage.getItem("userinfo"));
                if ($scope.usertoken != undefined && $scope.usertoken != null && $scope.usertoken != "") {
                    if ($scope.oldUserinfo != undefined && $scope.oldUserinfo != null && $scope.oldUserinfo != "") {
                        Restangular.addFullRequestInterceptor(function (element, operation, route, url, headers, params, httpConfig) {
                            //这个地方需要把登录得到的token写入到请求数据的头文件中
                            var usertoken = sysUserInfo.getuserinfotoken().toString();
                            if (usertoken == undefined || usertoken == null || usertoken == "") {
                                sysUserInfo.clearuserinfo();
                            }
                            return {
                                headers: { "X-Session-Token": usertoken, "Content-Type": "application/x-www-form-urlencoded;charset=utf-8" }
                            };
                        });
                        //获
                        RPS.personnelGetKey({ user_ID: $scope.oldUserinfo.user_ID }).then(function (retobj) {
                            if (retobj.errorcode == 0) {
                                retobj.data.userId = retobj.data.user_ID;
                                retobj.data.username = retobj.data.user_Name;
                                if (retobj.data.user_Img == "" || retobj.data.user_Img == null || retobj.data.user_Img == undefined) {
                                    retobj.data.user_Img = "/images/avatar.png";
                                }
                                if (retobj.data.userOrgList == undefined) {
                                    retobj.data.userOrgList = [];
                                }
                                if (retobj.data.userRoleList == undefined) {
                                    retobj.data.userRoleList = [];
                                }
                                if (retobj.data.userGroupList == undefined) {
                                    retobj.data.userGroupList = [];
                                }
                                sysUserInfo.setuserinfo(retobj.data);

                                if (retobj.data.powerLV == 99) {//学员登录                                
                                    window.location.href = "/member/index.html";
                                } else {
                                    window.location.href = "/system/index.html";
                                }
                            } else if (retobj.errorcode == "43") {
                                $scope.loginerr = true;
                                $scope.loginerrmsg = "企业套餐已过期，请续费";
                            } else if (retobj.errorcode == "44") {
                                $scope.loginerr = true;
                                $scope.loginerrmsg = "此账号已离职/结业，无法登录！";
                            } else if (retobj.errorcode == "68") {
                                $scope.loginerr = true;
                                $scope.loginerrmsg = "此账号已在别处登录！";
                            }
                        });
                    }
                }
            } catch (e) {
                console.log("获取历史登录信息异常！");
            }
            //更新验证码
            $scope.upd_yzm = function () {
                //Restangular.one("/ApiUser/").customGET("verifyCode",
                RM.verifyCode({ useraccount: $scope.username }).then(function (users) {
                    if (users.errorcode == 0) {
                        $scope.loginerr = false;
                        $scope.valimgurl = users.imgsrc;
                    } else {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "验证码获取失败！";
                    }
                }, function errorCallback() {
                    $scope.loginerr = true;
                    $scope.loginerrmsg = "连接服务器失败！";
                });
            }
            $scope.errorInput = function(myForm){
                if(myForm.username.$error.pattern){
                    $scope.isshow = true;
                    $scope.inputmsg = "邮箱/手机/用户名错误，请重新输入"
                }else if(myForm.username.$error.required){
                    $scope.isshow = true;
                    $scope.change = true
                    $scope.inputmsg ="邮箱/手机/用户名不能为空，请重新输入"
                }
            }
            $scope.errorInput1 = function(myForm){
                if(myForm.password.$error.required){
                    $scope.isshow1 = true;
                    $scope.change1 = true
                    $scope.inputmsg1 ="密码不能为空，请重新输入"
                }else if(myForm.username.$error.pattern){
                    $scope.isshow = true;
                    $scope.change = true
                    $scope.inputmsg1 ="密码错误，请重新输入"
                } 
                
            }
            $scope.QueryString = function (fieldName) {
                /// <summary>
                ///   获得URL GET参数  
                /// </summary>
                /// <param name="fieldName" type="String">
                ///   参数名
                /// </param>
                /// <returns type="void" />如果不存在返回NULL
                var reg = new RegExp("(^|&)" + fieldName + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }
            //用户登录
            $scope.user_login = function () {
                $scope.logmsg = "登 录 中";
                //Restangular.one("/ApiUser/").customPOST({ name: "My Message" }, "login", hex_md5($scope.password).toUpperCase()
                
                RM.login({ useraccount: $scope.username, userpwd: hex_md5($scope.password).toUpperCase(), code: $scope.yanzhengma }).then(function (users) {
                    $scope.logmsg = "登 录";
                    //用户登录错误次数 >5 <10 显示验证码 ，>10 锁定帐号
                    // errorcode  0登录成功 11账号被锁定1小时 12账户或密码有错误 13该用户已经登录 5连接不上数据库 14验证码错误
                    //                    console.log(users.name);
                    if (users.errorcode == "43") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "企业套餐已过期！";
                    } else if (users.errorcode == "38") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = users.errormsg;
                    } else if (users.errorcode == "44") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "此账号已离职/结业，无法登录！";
                    } else if (users.errorcode == "11") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "账号被锁定1小时！";
                    } else if (users.errorcode == "13") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "该用户已经登录！";
                    } else if (users.errorcode == "5") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "连接不上数据库！";
                    } else if (users.errorcode == "14") {
                        $scope.upd_yzm();
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "验证码错误！";
                    } else if (users.errorcode == "15") {
                        $scope.upd_yzm();
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "请重新输入图片验证码！";
                    } else if (users.errorcode == "6") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "系统错误！";
                    } else if (users.errorcode == "43") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "企业套餐已过期，请续费";
                    } else if (users.errorcode == "44") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "此账号已离职/结业，无法登录！";
                    } else if (users.errorcode == "68") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "此账号已在别处登录！";
                    } else if (users.errorcode == "28") {
                        $scope.loginerr = true;

                        $scope.loginerrmsg = users.errormsg;
                    } else if (users.errorcode == "12") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "密码错误, 请重新输入！";
                    } else if (users.errorcode == "16") {
                        $scope.loginerr = true;
                        $scope.loginerrmsg = "账号不存在！";
                    } else if (users.errorcode == "0") {
                        if (users.data.userstate == "0" || users.data.userstate == "3") {

                            if (users.data.userstate == "3") {
                                localStorage.setItem("flag", "noinfo");
                            } else {
                                localStorage.setItem("flag", "");
                            }

                            sysUserInfo.setuserinfotoken(users.token);
                            Restangular.addFullRequestInterceptor(function (element, operation, route, url, headers, params, httpConfig) {
                                //这个地方需要把登录得到的token写入到请求数据的头文件中
                                var usertoken = sysUserInfo.getuserinfotoken().toString();
                                if (usertoken == undefined || usertoken == null || usertoken == "") {
                                    sysUserInfo.clearuserinfo();
                                }
                                return {
                                    headers: { "X-Session-Token": usertoken, "Content-Type": "application/x-www-form-urlencoded;charset=utf-8" }
                                };
                            });
                            //获取用户信息
                            RPS.personnelGetKey({ user_ID: users.data.userId }).then(function (retobj) {
                                if (retobj.errorcode == 0) {
                                    retobj.data.userId = retobj.data.user_ID;
                                    retobj.data.username = retobj.data.user_Name;
                                    if (retobj.data.user_Img == "" || retobj.data.user_Img == null || retobj.data.user_Img == undefined) {
                                        retobj.data.user_Img = "/images/avatar.png";
                                    }
                                    if (retobj.data.userOrgList == undefined) {
                                        retobj.data.userOrgList = [];
                                    }
                                    if (retobj.data.userRoleList == undefined) {
                                        retobj.data.userRoleList = [];
                                    }
                                    if (retobj.data.userGroupList == undefined) {
                                        retobj.data.userGroupList = [];
                                    }
                                    sysUserInfo.setuserinfo(retobj.data);
                                    $rootScope.systemTitle = retobj.data.organization_Name;
                                    if ($scope.QueryString("url") != undefined) {
                                        window.location.href = $scope.QueryString("url");
                                    } else {
                                        if (users.data.powerLV == 99) {//学员登录                                
                                            window.location.href = "/member/index.html";
                                        } else {
                                            window.location.href = "/system/index.html";
                                        }
                                    }
                                } else if (retobj.errorcode == "43") {
                                    $scope.loginerr = true;
                                    $scope.loginerrmsg = "企业套餐已过期，请续费";
                                } else if (retobj.errorcode == "44") {
                                    $scope.loginerr = true;
                                    $scope.loginerrmsg = "此账号已离职/结业，无法登录！";
                                }
                            });
                        } else if (users.data.userstate == "4") {
                            $scope.loginerr = true;
                            $scope.loginerrmsg = "帐号未激活，请联系管理员！";
                            console.log("帐号未激活！");
                        } else if (users.data.userstate == "1") {
                            $scope.loginerr = true;
                            $scope.loginerrmsg = "帐号已冻结，请联系系统管理员！";
                            console.log("帐号已冻结！");
                        } else if (users.data.userstate == "2") {
                            $scope.loginerr = true;
                            $scope.loginerrmsg = "帐号锁定，请联系系统管理员！";
                            console.log("帐号锁定！");
                        } else if (users.data.userstate == "6") {
                            $scope.loginerr = true;
                            $scope.loginerrmsg = "注册审核未通过，请联系管理员！";
                            console.log("帐号锁定！");
                        }

                    }
                }, function errorCallback() {
                    $scope.loginerr = true;
                    $scope.loginerrmsg = "连接服务器失败！";
                });
            }
        } ]);
    </script>
    <script src="/system/service/userpathservice.js" type="text/javascript"></script>
    <script src="/system/service/personnelpathservice.js" type="text/javascript"></script>
    <script src="/framework/md5.js" type="text/javascript"></script>
</body>
</html>
